using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Collections;
using System.Management;
using Microsoft.Win32;
using System.IO;

//Used for the Mouse drag effect...
using System.Runtime.InteropServices;

namespace Computer_ID_Ver_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            if (Environment.OSVersion.Version.Major < 6)
            {
                OSXP = true;
            }
        }

        //true of app in running on Windows XP
        bool OSXP = false;

        //Used for holding HDD infomation..
        ArrayList hdCollection = new ArrayList();
        int Num_Hdd = 0;
        double TotalSize = 0;
        double TotalSpaceLeft = 0;
        bool HDD_info_Done = false;
        TextBox myHDDHtml = new TextBox();

        //Used for holding CPU infomation
        ArrayList CpuCollection = new ArrayList();
        bool CPU_Info_Done = false;
        TextBox myCPUHtml = new TextBox();

        //Used for holding Motherbord Infomation
        ArrayList MotherBoardCollection = new ArrayList();
        bool Main_board_done = false;
        float total_ram = 0;
        TextBox myMainBoardHtml = new TextBox();

        //Used for Graphic Card infomation
        ArrayList GraphicsCollection = new ArrayList();
        bool Graphics_infoget_done = false;
        TextBox myGraphicsHtml = new TextBox();

        //Used for holding Windows infomation
        ArrayList WindowsCollection = new ArrayList();
        bool windows_getinfo_done = false;
        TextBox myWindowsHtml = new TextBox();

        //const and dll functions for moving form
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;

        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd,
            int Msg, int wParam, int lParam);

        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();

        //Got ot from http://www.csharphelp.com/board2/read.html?f=1&i=11982&t=11982
        static System.DateTime ToDateTime(string dmtfDate)
        {
            //There is a utility called mgmtclassgen that ships with the .NET SDK that
            //will generate managed code for existing WMI classes. It also generates
            // datetime conversion routines like this one.
            //Thanks to Chetan Parmar and dotnet247.com for the help.
            int year = System.DateTime.Now.Year;
            int month = 1;
            int day = 1;
            int hour = 0;
            int minute = 0;
            int second = 0;
            int millisec = 0;
            string dmtf = dmtfDate;
            string tempString = System.String.Empty;

            if (((System.String.Empty == dmtf) || (dmtf == null)))
            {
                return System.DateTime.MinValue;
            }

            if ((dmtf.Length != 25))
            {
                return System.DateTime.MinValue;
            }

            tempString = dmtf.Substring(0, 4);
            if (("****" != tempString))
            {
                year = System.Int32.Parse(tempString);
            }

            tempString = dmtf.Substring(4, 2);

            if (("**" != tempString))
            {
                month = System.Int32.Parse(tempString);
            }

            tempString = dmtf.Substring(6, 2);

            if (("**" != tempString))
            {
                day = System.Int32.Parse(tempString);
            }

            tempString = dmtf.Substring(8, 2);

            if (("**" != tempString))
            {
                hour = System.Int32.Parse(tempString);
            }

            tempString = dmtf.Substring(10, 2);

            if (("**" != tempString))
            {
                minute = System.Int32.Parse(tempString);
            }

            tempString = dmtf.Substring(12, 2);

            if (("**" != tempString))
            {
                second = System.Int32.Parse(tempString);
            }

            tempString = dmtf.Substring(15, 3);

            if (("***" != tempString))
            {
                millisec = System.Int32.Parse(tempString);
            }

            System.DateTime dateRet = new System.DateTime(year, month, day, hour, minute, second, millisec);

            return dateRet;
        }

        //Got it from http://geekswithblogs.net/willemf/archive/2006/04/23/76125.aspx
        public static string DecodeProductKey(byte[] digitalProductId)
        {
            // Offset of first byte of encoded product key in 
            //  'DigitalProductIdxxx" REG_BINARY value. Offset = 34H.
            const int keyStartIndex = 52;
            // Offset of last byte of encoded product key in 
            //  'DigitalProductIdxxx" REG_BINARY value. Offset = 43H.
            const int keyEndIndex = keyStartIndex + 15;
            // Possible alpha-numeric characters in product key.
            char[] digits = new char[]
      {
        'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 
        'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9',
      };
            // Length of decoded product key
            const int decodeLength = 29;
            // Length of decoded product key in byte-form.
            // Each byte represents 2 chars.
            const int decodeStringLength = 15;
            // Array of containing the decoded product key.
            char[] decodedChars = new char[decodeLength];
            // Extract byte 52 to 67 inclusive.
            ArrayList hexPid = new ArrayList();
            for (int i = keyStartIndex; i <= keyEndIndex; i++)
            {
                hexPid.Add(digitalProductId[i]);
            }
            for (int i = decodeLength - 1; i >= 0; i--)
            {
                // Every sixth char is a separator.
                if ((i + 1) % 6 == 0)
                {
                    decodedChars[i] = '-';
                }
                else
                {
                    // Do the actual decoding.
                    int digitMapIndex = 0;
                    for (int j = decodeStringLength - 1; j >= 0; j--)
                    {
                        int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
                        hexPid[j] = (byte)(byteValue / 24);
                        digitMapIndex = byteValue % 24;
                        decodedChars[i] = digits[digitMapIndex];
                    }
                }
            }
            return new string(decodedChars);
        }

        //Used for cleaning up::::::::::::::::::::
        private void CleanUP()
        {
            //HDD Clean up::::::::::::::::::
            hdCollection.Clear();
            Num_Hdd = 0;
            TotalSize = 0;
            TotalSpaceLeft = 0;
            myHDDHtml.Clear();

            //CPU Clean up::::::::::::::::::
            CpuCollection.Clear();
            myCPUHtml.Clear();

            //MotherBoard Clean up::::::::::
            MotherBoardCollection.Clear();
            myMainBoardHtml.Clear();
            total_ram = 0;

            //Graphics Clean up::::::::::::
            GraphicsCollection.Clear();
            myGraphicsHtml.Clear();

            //Windows Clean up:::::::::::::
            WindowsCollection.Clear();
            myWindowsHtml.Clear();
        }

        //Used for calculating and "writing" the low tech progress bar under
        //the HDD infomation  i.e  [|||_______] 30 %
        private string CalCProcentLeft_For_HDD_info(double TotalSize_calc,double TotalFreeSpace_calc)
        {
            double x = 0;
            double y = 0;
            double procent = 0;

            //Make Values to GB:::::
            x = (((TotalSize_calc / 1024) / 1024) / 1024);
            y = (((TotalFreeSpace_calc / 1024) / 1024) / 1024);

            procent = ((y / x) * 100);
            procent = Math.Round(procent, 0);
            //procent = 100 - procent;

            x = 0;
            y = 0;

            #region make low tech progress bar, Not to accurate but it works
            bool found = false;

            // procent over than 10 %
            if (found != true)
            {
                if (procent <= 9)
                {
                    found = true;
                    return "[__________] " + procent + "%";
                }
            }

            // procent over than 10 %
            if (found != true)
            {
                if (procent <= 9)
                {
                    found = true;
                    return "[|_________] " + procent + "%";
                }
            }

            // procent over than 20 %
            if (found != true)
            {
                if (procent <= 19)
                {
                    found = true;
                    return "[||________] " + procent + "%";
                }
            }

            // procent over than 30 %
            if (found != true)
            {
                if (procent <= 29)
                {
                    found = true;
                    return "[|||_______] " + procent + "%";
                }
            }

            // procent over than 40 %
            if (found != true)
            {
                if (procent <= 39)
                {
                    found = true;
                    return "[||||______] " + procent + "%";
                }
            }

            // procent over than 50 %
            if (found != true)
            {
                if (procent <= 49)
                {
                    found = true;
                    return "[|||||_____] " + procent + "%";
                }
            }

            // procent over than 60 %
            if (found != true)
            {
                if (procent <= 59)
                {
                    found = true;
                    return "[||||||____] " + procent + "%";
                }
            }

            // procent over than 70 %
            if (found != true)
            {
                if (procent <= 69)
                {
                    found = true;
                    return "[|||||||___] " + procent + "%";
                }
            }

            // procent over than 80 %
            if (found != true)
            {
                if (procent <= 79)
                {
                    found = true;
                    return "[||||||||__] " + procent + "%";
                }
            }

            // procent over than 90 %
            if (found != true)
            {
                if (procent <= 89)
                {
                    found = true;
                    return "[|||||||||_] " + procent + "%";
                }
            }

            // procent 100 & than
            if (found != true)
            {
                if (procent <= 100)
                {
                    found = true;
                    return "[||||||||||] " + procent + "%";
                }
            }

            #endregion

            return "0";

        }

        //Does what it says, updates browser:::::::::::::::
        private int UpdateBrowser(string url)
        {
            //update webbrowser1
            webBrowser1.DocumentText = url;
            webBrowser1.Update();

            return 0;
        }
        
        //HDD::::::::::::::::::::::::::::::::::::::
        private void GetHardDiskInfo()
        {
            #region HDD_Collction of Infomation

            hdCollection.Clear();
            HDD_info_Done = false;
            Num_Hdd = 0;
            TotalSize = 0;
            TotalSpaceLeft = 0;

            //Hdd_TextBox.Text = "";
            //ArrayList hdCollection = new ArrayList();

            ManagementObjectSearcher searcher = new
            ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

                foreach (ManagementObject wmi_HD in searcher.Get())
                {
                   HardDrive hd = new HardDrive();

                    #region hd.Model
                   try
                    {
                        hd.Model = wmi_HD["Model"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.Model = "Unknown";
                    }
                   #endregion

                    #region hd.Type
                    try
                    {
                        hd.Type = wmi_HD["InterfaceType"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.Type = "Unknown";
                    }
                    #endregion

                    #region hd.BytesPerSector
                    try
                    {
                        hd.BytesPerSector = wmi_HD["BytesPerSector"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.BytesPerSector = "Unknown";
                    }
                    #endregion

                    #region hd.MediaType
                    try
                    {
                        hd.MediaType = wmi_HD["MediaType"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.MediaType = "Unknown";
                    }
                    #endregion

                    #region hd.Partitions
                    try
                    {
                        hd.Partitions = wmi_HD["Partitions"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.Partitions = "Unknown";
                    }
                    #endregion

                    #region hd.SectorsPerTrack
                    try
                    {
                        hd.SectorsPerTrack = wmi_HD["SectorsPerTrack"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.SectorsPerTrack = "Unknown";
                    }
                    #endregion

                    #region hd.Signature
                    try
                    {
                        hd.Signature = wmi_HD["Signature"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.Signature = "Unknown";
                    }
                    #endregion

                    #region hd.size
                    try
                    {
                        hd.Size = wmi_HD["Size"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.Size = "0";
                    }
                    #endregion

                    #region hd.Status
                    try
                    {
                        hd.Status = wmi_HD["Status"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.Status = "Unknown";
                    }
                    #endregion

                    #region hd.TotalCylonders
                    try
                    {
                        hd.TotalCylinders = wmi_HD["TotalCylinders"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.TotalCylinders = "Unknown";
                    }
                    #endregion

                    #region hd.TotalHeads
                    try
                    {
                        hd.TotalHeads = wmi_HD["TotalHeads"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.TotalHeads = "Unknown";
                    }
                    #endregion

                    #region hd.TotalSectors
                    try
                    {
                        hd.TotalSectors = wmi_HD["TotalSectors"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.TotalSectors = "Unknown";
                    }
                    #endregion

                    #region hd.TotalTracks
                    try
                    {
                        hd.TotalTracks = wmi_HD["TotalTracks"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.TotalTracks = "Unknown";
                    }
                    #endregion

                    #region hd.TracksPerCylinder
                    try
                    {
                        hd.TracksPerCylinder = wmi_HD["TracksPerCylinder"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        hd.TracksPerCylinder = "Unknown";
                    }
                    #endregion

                    #region hd.SeralNo

                    if (OSXP != true)
                    {
                        try
                        {
                            hd.SerialNo = wmi_HD["SerialNumber"].ToString();
                        }
                        catch (NullReferenceException)
                        {
                            hd.SerialNo = "Unknown";
                        }
                    }
                    else
                    {

                    }
                    #endregion

                    hdCollection.Add(hd);

                    Num_Hdd = Num_Hdd + 1;
                    TotalSize = TotalSize + double.Parse(wmi_HD["Size"].ToString());

                }

               //Getting HDD's serial under XP 
               if (OSXP == true)
                {
                    searcher = new
                        ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

                    int i = 0;
                    foreach (ManagementObject wmi_HD in searcher.Get())
                    {
                        // get the hard drive from collection
                        // using index
                        HardDrive hd = (HardDrive)hdCollection[i];

                        // get the hardware serial no.
                        if (wmi_HD["SerialNumber"] == null)
                            hd.SerialNo = "None";
                        else
                            hd.SerialNo = wmi_HD["SerialNumber"].ToString();

                        ++i;
                    }
                }

                searcher = new
                    ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk");

                foreach (ManagementObject wmi_HD in searcher.Get())
                {

                    // get how much Freespace the HDD have left...
                    if (wmi_HD["FreeSpace"] == null)
                    {
                        //do nothing
                    }
                    else
                    {
                        if (wmi_HD["DriveType"].ToString() == "3")
                        {
                            TotalSpaceLeft += double.Parse(wmi_HD["FreeSpace"].ToString());
                        }
                    }
                }

                HDD_info_Done = true;

            #endregion
            }

        private void WriteHDDHtml()
        {
            if (HDD_info_Done == true)
            {
                myHDDHtml.Text = "";
                myHDDHtml.Text = (
                    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" +
                    "<html>" +
                    "<head>" +
                    "<STYLE type=text/css>" + 
                    "BODY {" + 
                    "SCROLLBAR-FACE-COLOR: #637B3B; " + 
                    "SCROLLBAR-HIGHLIGHT-COLOR: #f3f3f3; " +
                    "SCROLLBAR-SHADOW-COLOR: #f3f3f3; " +
                    "SCROLLBAR-ARROW-COLOR: #000000; " +
                    "SCROLLBAR-BASE-COLOR: #6d8693; " +
                    "scrollbar-dark-shadow-color: black; " +
                    "scrollbar-3d-light-color: #9BAAC1 " +
                    "}" +
                    "</STYLE>" +
                    "<title>Model:</title>" +
                    "</head>" +
                    "<body bgcolor=\"black\" text=\"#637B3B\" link=\"black\" vlink=\"black\" alink=\"black\"> ");
                    
                    foreach (HardDrive hd in hdCollection)
                    {
                        double size_temp = double.Parse(hd.Size);

                    myHDDHtml.Text += (
                    "<p><font face=\"Verdana\" size=\"1\">Model: " + hd.Model +"<br>" + 
                    "Serial: " + hd.SerialNo + "<br>" +
                    "Type: " + hd.Type + "<br><br>" +
                    "Partittions: " + hd.Partitions + "<br>" + 
                    "Signature: " + hd.Signature + "<br>" +
                    "Size: " + hd.Size + " Byte &nbsp; (" + Math.Round((((size_temp / 1024) / 1024) / 1024), 2)  + " GB)<br><br>" +
                    "</font>" +
                    "</p>" +
                    "<table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"320\">" + 
                    "<tr>" +
                    "<td width=\"366\" valign=\"top\" style=\"border-right-width:thin; border-right-color:rgb(99,123,59); border-right-style:solid;\">" +
                    "<p><font face=\"Verdana\" size=\"1\">" +
                    "Total Cylinders: " + hd.TotalCylinders + "<br>" +
                    "Total Heads: " + hd.TotalHeads + "<br>" +
                    "Total Sectors: " + hd.TotalSectors + "<br>" + 
                    "Total Tracks: " + hd.TotalTracks +
                    "</font></p>" +
                    "</td>" +
                    " <td width=\"366\" valign=\"top\" style=\"border-style:none;\">" + 
                    "<p align=\"right\"><font face=\"Verdana\" size=\"1\">" +
                    "Bytes pr. Sector: " + hd.BytesPerSector + "<br>" +
                    "Sectors pr. Track: " + hd.SectorsPerTrack + "<br>" +
                    "Tracks pr. Cylinder: " + hd.TracksPerCylinder +
                    "</font></p></td></tr></table>" + 
                    "<hr noshade color=\"#637B3B\">"
                    );
                    
                    }
                    
                    //Total::::
                myHDDHtml.Text += (
                    "<center><font face=\"Verdana\" size=\"1\">----= Total =----</font></center>" +
                    "<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"280\">" +
                    "<tr>" +
                    "<td width=\"477\"><p align=\"left\"><font face=\"Verdana\" size=\"1\">" +
                    "Number of HDD's : " + Num_Hdd + "<br>" +
                    "Capacity: " + Math.Round((((TotalSize / 1024) / 1024) / 1024), 2) + " GB<br>" +
                    "Space Left: " + Math.Round(((((TotalSpaceLeft / 1024) / 1024)) / 1024), 2) + " GB<br></font></p>" +
                    "</td>" +
                    "<td width=\"477\">" +
                    "<p><font face=\"Verdana\" size=\"1\"><br><br>" +
                    "&nbsp;" + CalCProcentLeft_For_HDD_info(TotalSize,TotalSpaceLeft) + "</font></p>" +
                    "</td>" +
                    "</tr>" +
                    "</table>" +
                    "</body></html>"
                    );                

            }
            else
            {
                //Do something.. or nothing... ?!
            }

        }

        //CPU::::::::::::::::::::::::::::::::::::::
        private void GetCPUInfo()
        {

            #region Cpu info search...

            CPU_Info_Done = false;

            CpuCollection.Clear();
            ManagementObjectSearcher searcher = new
            ManagementObjectSearcher("SELECT * FROM Win32_Processor");

                foreach (ManagementObject wmi_Cpu in searcher.Get())
                {
                    Cpu mycpu = new Cpu();

                    #region mycpu.Manufacturer = wmi_Cpu["Manufacturer"].ToString();
                    try
                    {
                        mycpu.Manufacturer = wmi_Cpu["Manufacturer"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.Manufacturer = "Unknown";
                    }
                    #endregion

                    #region mycpu.Architecture = wmi_Cpu["Architecture"].ToString();
                    try
                    {
                        mycpu.Architecture = wmi_Cpu["Architecture"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.Architecture = "10";
                    }

                    switch (mycpu.Architecture)
                    {
                        case "0":
                            mycpu.Architecture = "x86";
                            break;
                        case "1":
                            mycpu.Architecture = "MIPS";
                            break;
                        case "2":
                            mycpu.Architecture = "Alpha";
                            break;
                        case "3":
                            mycpu.Architecture = "PowerPC";
                            break;
                        case "6":
                            mycpu.Architecture = "Intel Itanium Processor Family (IPF)";
                            break;
                        case "9":
                            mycpu.Architecture = "x64";
                            break;
                        case "10":
                            mycpu.Architecture = "Unknown";
                            break;
                    }

                    #endregion

                    #region mycpu.CurrentClockSpeed = wmi_Cpu["CurrentClockSpeed"].ToString();
                    try
                    {
                        mycpu.CurrentClockSpeed = wmi_Cpu["CurrentClockSpeed"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.CurrentClockSpeed = "Unknown";
                    }
                    #endregion

                    #region mycpu.CurrentVoltage = wmi_Cpu["CurrentVoltage"].ToString();
                    try
                    {
                        mycpu.CurrentVoltage = wmi_Cpu["CurrentVoltage"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.CurrentVoltage = "0";
                    }
                    #endregion

                    #region mycpu.Description = wmi_Cpu["Description"].ToString();
                    try
                    {
                        mycpu.Description = wmi_Cpu["Description"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.Description = "Unknown";
                    }
                    #endregion

                    #region mycpu.Name = wmi_Cpu["Name"].ToString();
                    try
                    {
                        mycpu.Name = wmi_Cpu["Name"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.Name = "Unknown";
                    }
                    #endregion

                    #region mycpu.ProcessorId = wmi_Cpu["ProcessorId"].ToString();
                    try
                    {
                        mycpu.ProcessorId = wmi_Cpu["ProcessorId"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.ProcessorId = "Unknown";
                    }
                    #endregion

                    #region mycpu.SocketDesignation = wmi_Cpu["SocketDesignation"].ToString();
                    try
                    {
                        mycpu.SocketDesignation = wmi_Cpu["SocketDesignation"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.SocketDesignation = "Unknown";
                    }
                    #endregion 

                    if (OSXP != true)
                    {
                        mycpu.Cores = int.Parse(wmi_Cpu["NumberOfCores"].ToString());
                    }

                    #region mycpu.ExtClock    //FSB value
                    try
                    {
                        mycpu.ExtClock = wmi_Cpu["ExtClock"].ToString(); //
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.ExtClock = "Unknown";
                    }
                    #endregion  
                    #region mycpu.L2CacheSize
                    try
                    {
                        mycpu.L2CacheSize = wmi_Cpu["L2CacheSize"].ToString(); //
                    }
                    catch (NullReferenceException)
                    {
                        mycpu.L2CacheSize = "Unknown";
                    }
                    #endregion


                    #region Droped CPU infomation
                     
                      #region mycpu.L2CacheSpeed
                    //try
                    //{
                    //    mycpu.L2CacheSpeed = wmi_Cpu["L2CacheSpeed"].ToString();
                    //}
                    //catch (NullReferenceException)
                    //{
                    //    mycpu.L2CacheSpeed = " Unknown";
                    //}
                    #endregion
                    //mycpu.DeviceID = wmi_Cpu["DeviceID"].ToString();
                    //mycpu.Caption = wmi_Cpu["Caption"].ToString(); 
                    //mycpu.DataWidth = wmi_Cpu["DataWidth"].ToString(); 
                    //mycpu.CpuStatus = wmi_Cpu["CpuStatus"].ToString(); 
                    //mycpu.Availability = wmi_Cpu["Availability"].ToString(); 
                    //mycpu.AddressWidth = wmi_Cpu["AddressWidth"].ToString(); 
                    //mycpu.MaxClockSpeed = wmi_Cpu["MaxClockSpeed"].ToString(); //
                    //mycpu.Level = wmi_Cpu["Level"].ToString();
                      #region CPU_Loadpercentage
                    //try
                    //{
                    //    mycpu.LoadPercentage = wmi_Cpu["LoadPercentage"].ToString(); //
                    //}
                    //catch (NullReferenceException)
                    //{
                    //    mycpu.LoadPercentage = "0";
                    //}
                    #endregion
                    //mycpu.PowerManagementSupported = wmi_Cpu["PowerManagementSupported"].ToString();
                    //mycpu.ProcessorType = wmi_Cpu["ProcessorType"].ToString();
                    //mycpu.Role = wmi_Cpu["Role"].ToString(); //
                    //mycpu.Status = wmi_Cpu["Status"].ToString(); //
                    //mycpu.StatusInfo = wmi_Cpu["StatusInfo"].ToString(); //
                    //mycpu.UpgradeMethod = wmi_Cpu["UpgradeMethod"].ToString(); //
                    //mycpu.Version = wmi_Cpu["Version"].ToString(); //
                    //mycpu.Family = wmi_Cpu["Family"].ToString(); //
                      #region mycpu.PowerManagementCapabilities
                    //try
                    //{
                    //    mycpu.PowerManagementCapabilities = wmi_Cpu["PowerManagementCapabilities"].ToString();
                    //}
                    //catch (NullReferenceException)
                    //{
                    //    mycpu.PowerManagementCapabilities = "Unknown";
                    //}
                    #endregion
                      #region mycpu.ConfigManagerErrorCode
                    //try
                    //{
                    //    mycpu.ConfigManagerErrorCode = wmi_Cpu["ConfigManagerErrorCode"].ToString();
                    //}
                    //catch (NullReferenceException)
                    //{
                    //    mycpu.ConfigManagerErrorCode = "Unknown";
                    //}
                    #endregion
                    #endregion

                    CpuCollection.Add(mycpu);
                }
                CPU_Info_Done = true;
            #endregion
        }

        private void WriteCPUHtml()
        {
            if (CPU_Info_Done != false)
            {

                myCPUHtml.Text = (
                    "<html>" +
                    "<head>" +
                    "<title>CPU Info</title>" +
                    "<STYLE type=text/css>>" +
                    "BODY { " +
                    "SCROLLBAR-FACE-COLOR: #637B3B; " +
                    "SCROLLBAR-HIGHLIGHT-COLOR: #f3f3f3; " +
                    "SCROLLBAR-SHADOW-COLOR: #f3f3f3; " +
                    "SCROLLBAR-ARROW-COLOR: #000000; " +
                    "SCROLLBAR-BASE-COLOR: #6d8693; " +
                    "scrollbar-dark-shadow-color: black; " +
                    "scrollbar-3d-light-color: #9BAAC1" +
                    "}" +
                    "</STYLE>" +
                    "</head>" +
                    "<body bgcolor=\"black\" text=\"#637B3B\" link=\"#637B3B\" vlink=\"#637B3B\" alink=\"#637B3B\">" +
                    "<font face=\"Verdana\" size=\"1\">");
                foreach (Cpu cpu in CpuCollection)
                    {
                        double currentVolt = double.Parse(cpu.CurrentVoltage);
                        currentVolt = currentVolt / 10;
                        currentVolt = Math.Round(currentVolt, 2);

                        myCPUHtml.Text += (
                        "Name: " + cpu.Name + "<br>" +
                        "Manufacturer: " + cpu.Manufacturer + "<br>" +
                        "Processor ID: " + cpu.ProcessorId + "<br><br></font></p>" +
                        "<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"320\">" + 
                        "<tr>" +
                        "<td width=\"160\" valign=\"top\" style=\"border-right-width:thin; border-right-color:rgb(99,123,59); border-right-style:solid;\">" +
                        "<p><font face=\"Verdana\" size=\"1\">" +
                        //"Speed:<br>" +
                        "ClockSpeed: " + cpu.CurrentClockSpeed + " MHz<br>" + 
                        "FSB: " + cpu.ExtClock + " MHz<br>" +
                        "Current Voltage:" + currentVolt.ToString() +" Volts</font></p>" +
                        "</td>" +
                        "<td width=\"160\" valign=\"top\">" +
                        "<p><font face=\"Verdana\" size=\"1\">" +
                        "L2 CacheSize: " + cpu.L2CacheSize + " KB<br>" +
                        "Architecture: " + cpu.Architecture + "<br>" +                        
                        "Socket: " + cpu.SocketDesignation + "<br>");

                        if (OSXP != true)
                        {
                            myCPUHtml.Text += ("Core's: " + cpu.Cores);
                        }
                    myCPUHtml.Text += (
                        "</font></p></td></tr></table><hr noshade color=\"#637B3B\"></body></html>"
                     );
                 }
            }

        }

        //MotherBoard::::::::::::::::::::::::::::::
        private void GetMotboardInfo()
        {
            MotherBoardCollection.Clear();
            total_ram = 0;

                #region Motherboard info...
                Main_board_done = false;
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");

                Motherboard myMotherboard = new Motherboard();
                foreach (ManagementObject wmi_myMotherboard in searcher.Get())
                {
                    myMotherboard.Manufacturer = wmi_myMotherboard["Manufacturer"].ToString();
                    myMotherboard.Product = wmi_myMotherboard["Product"].ToString();
                    myMotherboard.Version = wmi_myMotherboard["Version"].ToString();
                }

                searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
                foreach (ManagementObject wmi_myMotherboard in searcher.Get())
                {
                    myMotherboard.Bios_Description = wmi_myMotherboard["Description"].ToString();
                    myMotherboard.Bios_Manufacturer = wmi_myMotherboard["Manufacturer"].ToString();
                    myMotherboard.Bios_ReleaseDate = wmi_myMotherboard["ReleaseDate"].ToString();

                    DateTime dc3 = ToDateTime(myMotherboard.Bios_ReleaseDate);
                    myMotherboard.Bios_ReleaseDate = dc3.AddTicks(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks).ToLocalTime().ToString();

                    myMotherboard.Bios_Version = wmi_myMotherboard["Version"].ToString();
                    myMotherboard.Bios_SMBIOSBIOSVersion = wmi_myMotherboard["SMBIOSBIOSVersion"].ToString();

                }

                searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory");
                foreach (ManagementObject wmi_myMotherboard in searcher.Get())
                {
                    myMotherboard.Ram_Capacity = wmi_myMotherboard["Capacity"].ToString();
                    total_ram = total_ram + float.Parse(myMotherboard.Ram_Capacity);
                }
                
                MotherBoardCollection.Add(myMotherboard);

                Main_board_done = true;

                #endregion
        }

        private void WriteMainBoardHtml()
        {
           if (Main_board_done != false)
            {
                myMainBoardHtml.Text = "";
                total_ram = ((total_ram / 1024) / 1024) ;
                 
               myMainBoardHtml.Text = 
                    (
                    "<html>" +
                    "<head>" +
                    "<title>CPU Info</title>" +
                    "<STYLE type=text/css>>" +
                    "BODY { " +
                    "SCROLLBAR-FACE-COLOR: #637B3B; " +
                    "SCROLLBAR-HIGHLIGHT-COLOR: #f3f3f3; " +
                    "SCROLLBAR-SHADOW-COLOR: #f3f3f3; " +
                    "SCROLLBAR-ARROW-COLOR: #000000; " +
                    "SCROLLBAR-BASE-COLOR: #6d8693; " +
                    "scrollbar-dark-shadow-color: black; " +
                    "scrollbar-3d-light-color: #9BAAC1" +
                    "}" +
                    "</STYLE>" +
                    "</head>" +
                    "<body bgcolor=\"black\" text=\"#637B3B\" link=\"#637B3B\" vlink=\"#637B3B\" alink=\"#637B3B\">" +
                    "<font face=\"Verdana\" size=\"1\">" +
                    "<p><font face=\"Verdana\" size=\"1\">" );
               foreach (Motherboard myMotherboard in MotherBoardCollection)
               {
                   myMainBoardHtml.Text += (
                    "Manufacturer: " + myMotherboard.Manufacturer + "<br>" +
                    "Model: " + myMotherboard.Product + "<br>" +
                    "Version: " + myMotherboard.Version + "<br><br>" +
                    "</font><font face=\"Verdana\" size=\"1\">" +
                    "BIOS:<br>" +
                    "Description: " + myMotherboard.Bios_Description + "<br>" +
                    "Manufacturer: " + myMotherboard.Bios_Manufacturer + "<br>" +
                    "Release Date: " + myMotherboard.Bios_ReleaseDate + "<br>" +
                    "BIOS Version: " + myMotherboard.Bios_Version + "<br><br>" +
                    "Ram installed: <br>" +
                    "Total: " + total_ram.ToString() +" MB" +
                    "</font><br></p></body></html>");
               }
           }

        }

        //Graphics:::::::::::::::::::::::::::::::::
        private void GetGraphicsCardInfo()
        {

            #region Graphics info....


                GraphicsCollection.Clear();
                Graphics_infoget_done = false;

                ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");

                foreach (ManagementObject wmi_myvideo in searcher.Get())
                {
                    Videocontroller myvideo = new Videocontroller();

                    #region myvideo.AdapterCompatibility = wmi_myvideo["AdapterCompatibility"].ToString();
                    try
                    {
                        myvideo.AdapterCompatibility = wmi_myvideo["AdapterCompatibility"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.AdapterCompatibility = "Unknown";
                    }
                    #endregion

                    #region myvideo.AdapterDACType = wmi_myvideo["AdapterDACType"].ToString();
                    try
                    {
                        myvideo.AdapterDACType = wmi_myvideo["AdapterDACType"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.AdapterDACType = "Unknown";
                    }
                    #endregion

                    #region myvideo.AdapterRAM = wmi_myvideo["AdapterRAM"].ToString();
                    try
                    {
                        myvideo.AdapterRAM = wmi_myvideo["AdapterRAM"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.AdapterRAM = "0";
                    }

                    float total_ram = float.Parse(myvideo.AdapterRAM);
                    myvideo.AdapterRAM = ((total_ram / 1024) / 1024) + " MB";

                    #endregion

                    myvideo.Caption = wmi_myvideo["Caption"].ToString();

                    #region myvideo.CurrentBitsPerPixel
                    try
                    {
                        myvideo.CurrentBitsPerPixel = wmi_myvideo["CurrentBitsPerPixel"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.CurrentBitsPerPixel = "";
                    }
                    #endregion

                    #region myvideo.CurrentHorizontalResolution
                    try
                    {
                        myvideo.CurrentHorizontalResolution = wmi_myvideo["CurrentHorizontalResolution"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.CurrentHorizontalResolution = "";
                    }
                    #endregion

                    #region myvideo.CurrentNumberOfColors
                    try
                    {
                        myvideo.CurrentNumberOfColors = wmi_myvideo["CurrentNumberOfColors"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.CurrentNumberOfColors = "";
                    }
                    #endregion

                    #region  myvideo.CurrentRefreshRate
                    try
                    {
                        myvideo.CurrentRefreshRate = wmi_myvideo["CurrentRefreshRate"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.CurrentRefreshRate = "";
                    }
                    #endregion

                    #region myvideo.CurrentScanMode
                    try
                    {
                        myvideo.CurrentScanMode = wmi_myvideo["CurrentScanMode"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.CurrentScanMode = "1";
                    }
                    #endregion

                    #region myvideo.CurrentVerticalResolution
                    try
                    {
                        myvideo.CurrentVerticalResolution = wmi_myvideo["CurrentVerticalResolution"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.CurrentVerticalResolution = "";
                    }
                    #endregion

                    myvideo.DriverDate = wmi_myvideo["DriverDate"].ToString();
                    DateTime dc3 = ToDateTime(myvideo.DriverDate);
                    myvideo.DriverDate = dc3.AddTicks(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks).ToLocalTime().ToString();

                    myvideo.DriverVersion = wmi_myvideo["DriverVersion"].ToString();
                    //myvideo.InfSection = wmi_myvideo["InfSection"].ToString();
                    
                    myvideo.InstalledDisplayDrivers = wmi_myvideo["InstalledDisplayDrivers"].ToString();
                    #region myvideo.MaxRefreshRate
                    try
                    {
                        myvideo.MaxRefreshRate = wmi_myvideo["MaxRefreshRate"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.MaxRefreshRate = "";
                    }
                    #endregion

                    #region myvideo.MinRefreshRate
                    try
                    {
                        myvideo.MinRefreshRate = wmi_myvideo["MinRefreshRate"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myvideo.MinRefreshRate = "";
                    }
                    #endregion

                    myvideo.Name = wmi_myvideo["Name"].ToString();

                    #region myvideo.VideoModeDescription
                    //try
                    //{
                    //    myvideo.VideoModeDescription = wmi_myvideo["VideoModeDescription"].ToString();
                    //}
                    //catch (NullReferenceException)
                    //{
                    //    myvideo.VideoModeDescription = "";
                    //}
                    #endregion

                    GraphicsCollection.Add(myvideo);
                    Graphics_infoget_done = true;

                }

                #endregion
        
        }

        private void WriteGraphicsHtml()
        {
            if (Graphics_infoget_done != false)
            {

                

                myGraphicsHtml.Text = (
                                        "<html>" +
                                        "<head>" +
                                        "<title></title>" +
                                        "<STYLE type=text/css>" +
                                        "BODY {" +
                                        "SCROLLBAR-FACE-COLOR: #637B3B; " +
                                        "SCROLLBAR-HIGHLIGHT-COLOR: #f3f3f3; " +
                                        "SCROLLBAR-SHADOW-COLOR: #f3f3f3; " +
                                        "SCROLLBAR-ARROW-COLOR: #000000; " +
                                        "SCROLLBAR-BASE-COLOR: #6d8693; " +
                                        "scrollbar-dark-shadow-color: black; " +
                                        "scrollbar-3d-light-color: #9BAAC1" +
                                        "}" +
                                        "</STYLE>" +
                                        "</head>" +
                                        "<body bgcolor=\"black\" text=\"#637B3B\" link=\"#637B3B\" vlink=\"#637B3B\" alink=\"#637B3B\">" +
                                        "");
                foreach (Videocontroller graphicscard in GraphicsCollection)
                {

                    #region Scan Mode
                    string ScanMode = "";
                    switch (graphicscard.CurrentScanMode)
                    {
                        case "1":
                            ScanMode = "Scan Mode : Other";
                            break;
                        case "2":
                            ScanMode = "Scan Mode : Unknown";
                            break;
                        case "3":
                            ScanMode = "Scan Mode : Interlaced";
                            break;
                        case "4":
                            ScanMode = "Scan Mode : Non Interlaced";
                            break;
                        default:
                            ScanMode = "Scan Mode : Unknown";
                            break;
                    }
                    #endregion

                    myGraphicsHtml.Text += (
                                        "<p><font face=\"Verdana\" size=\"1\">" +
                                        "Name: " + graphicscard.Name + "<br>" +
                                        "Manufacturer: " + graphicscard.AdapterCompatibility + "<br>" +
                                        "DAC: " + graphicscard.AdapterDACType + "<br>" +
                                        "Ram: " + graphicscard.AdapterRAM + "<br>" +
                                        "</font></p>" +
                                        "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"320\">" +
                                        "<tr>" +
                                        "<td width=\"401\" valign=\"top\" style=\"border-right-width:thin; border-right-color:rgb(99,123,59); border-right-style:solid;\">" +
                                        "<p><font face=\"Verdana\" size=\"1\">" +
                                        "Resolution: " + graphicscard.CurrentHorizontalResolution + " X " + graphicscard.CurrentVerticalResolution + " Pixel" + "<br>" +
                                        "Colors: " + graphicscard.CurrentNumberOfColors + "<br>" +
                                        "Refresh Rate: " + graphicscard.CurrentRefreshRate + "<br>" +
                                        ScanMode + "<br>" +
                                        "</font></p>" +
                                        "</td>" +
                                        "<td width=\"401\" valign=\"top\">" +
                                        "<p align=\"right\"><font face=\"Verdana\" size=\"1\">" +
                                        "Bits per Pixel: " + graphicscard.CurrentBitsPerPixel +" bit<br>" +
                                        "Max Refresh Rate: " + graphicscard.MaxRefreshRate +" Hz<br>" +
                                        "Min Refresh Rate: " + graphicscard.MinRefreshRate + " Hz<br>" +
                                        "</font></p>" +
                                        "</td>" +
                                        "</tr>" +
                                        "</table>" +
                                        "<p><font face=\"Verdana\" size=\"1\">" +
                                        "Drivers:<br>" +
                                        "Driver Date: " + graphicscard.DriverDate +"<br>" +
                                        "Driver Version: " + graphicscard.DriverVersion +"<br>" +
                                        "Display Drivers: " + graphicscard.InstalledDisplayDrivers +
                                        "</font></p><hr noshade color=\"#637B3B\"></body></html>");
                }
            }
        }

        //Windows::::::::::::::::::::::::::::::::::
        private void GetWindowsInfo()
        {
            WindowsCollection.Clear();
            windows_getinfo_done = false;

            try
            {
                #region Windows Info....

                ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");

                Windows myWindows = new Windows();
                foreach (ManagementObject wmi_Windows in searcher.Get())
                {
                    myWindows.BuildNumber = wmi_Windows["BuildNumber"].ToString();
                    myWindows.Caption = wmi_Windows["Caption"].ToString();
                    myWindows.CountryCode = wmi_Windows["CountryCode"].ToString();
                    #region myWindows.CSDVersion
                    try
                    {
                        myWindows.CSDVersion = wmi_Windows["CSDVersion"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myWindows.CSDVersion = "Unknown, or no service pack installed";
                    }
                    #endregion
                    myWindows.Description = wmi_Windows["Description"].ToString();
                    myWindows.EncryptionLevel = wmi_Windows["EncryptionLevel"].ToString();
                    myWindows.FreePhysicalMemory = wmi_Windows["FreePhysicalMemory"].ToString();
                    myWindows.RegisteredUser = wmi_Windows["RegisteredUser"].ToString();

                    myWindows.InstallDate = wmi_Windows["InstallDate"].ToString();
                    DateTime dc = ToDateTime(myWindows.InstallDate);
                    myWindows.InstallDate = dc.AddTicks(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks).ToLocalTime().ToString();

                    #region System up time
                    myWindows.LastBootUpTime = wmi_Windows["LastBootUpTime"].ToString();
                    DateTime dc2 = ToDateTime(myWindows.LastBootUpTime);
                    DateTime date1 = dc2.AddTicks(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks).ToLocalTime();
                    DateTime date2 = DateTime.Now;
                    TimeSpan dateresult = date2 - date1;
                    //Windows_LastBootUpTime_txt.Text = "System Up Time : " + dc2.AddTicks(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks).ToLocalTime().ToString() + " || " + DateTime.Now ;
                    myWindows.LastBootUpTime = dateresult.Days + " Day/s  " + dateresult.Hours + "h :" + dateresult.Minutes + "m :" + dateresult.Seconds + "s";
                    #endregion

                    #region myWindows.NumberOfLicensedUsers
                    try
                    {
                        myWindows.NumberOfLicensedUsers = wmi_Windows["NumberOfLicensedUsers"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myWindows.NumberOfLicensedUsers = "Unknown";
                    }
                    #endregion
                    #region myWindows.Organization
                    try
                    {
                        myWindows.Organization = wmi_Windows["Organization"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        myWindows.Organization = "";
                    }
                    #endregion
                    myWindows.SerialNumber = wmi_Windows["SerialNumber"].ToString();
                    myWindows.TotalVirtualMemorySize = wmi_Windows["TotalVirtualMemorySize"].ToString();
                    myWindows.TotalVisibleMemorySize = wmi_Windows["TotalVisibleMemorySize"].ToString();
                    myWindows.Version = wmi_Windows["Version"].ToString();
                    //myWindows.ProductType = wmi_Windows["ProductType"].ToString();
                    //myWindows.ServicePackMajorVersion = wmi_Windows["ServicePackMajorVersion"].ToString();
                    //myWindows.ServicePackMinorVersion = wmi_Windows["ServicePackMinorVersion"].ToString();
                    //myWindows.FreeSpaceInPagingFiles = wmi_Windows["FreeSpaceInPagingFiles"].ToString();
                    //myWindows.BuildType = wmi_Windows["BuildType"].ToString();

                }

                #region Windows_Productkey_txt.Text
                try
                {
                    //byte[] digitalProductId = null;
                    //RegistryKey hklm = Registry.LocalMachine;
                    //hklm = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
                    //digitalProductId = hklm.GetValue("DigitalProductId") as byte[];
                    //Windows_Productkey_txt.Text = "Product key : " + DecodeProductKey(digitalProductId);
                }
                catch (NullReferenceException)
                {
                    //Windows_Productkey_txt.Text = "Unknown";
                }
                #endregion

                WindowsCollection.Add(myWindows);
                windows_getinfo_done = true;
                #endregion
            }
            catch (Exception i4)
            {
                MessageBox.Show(i4.ToString());
            }

        }

        private void WriteWindowsHtml()
        {

            if (windows_getinfo_done != false)
            {
                myWindowsHtml.Text = "";

            myWindowsHtml.Text = (
                                    "<html>" +
                                    "<head>" +
                                    "<title></title>" + 
                                    "<STYLE type=text/css>" +
                                    "BODY {" +
                                    "SCROLLBAR-FACE-COLOR: #637B3B; " +
                                    "SCROLLBAR-HIGHLIGHT-COLOR: #f3f3f3; " +
                                    "SCROLLBAR-SHADOW-COLOR: #f3f3f3; " +
                                    "SCROLLBAR-ARROW-COLOR: #000000; " +
                                    "SCROLLBAR-BASE-COLOR: #6d8693; " +
                                    "scrollbar-dark-shadow-color: black; " +
                                    "scrollbar-3d-light-color: #9BAAC1" +
                                    "}" +
                                    "</STYLE>" +
                                    "</head>" +
                                    "<body bgcolor=\"black\" text=\"#637B3B\" link=\"#637B3B\" vlink=\"#637B3B\" alink=\"#637B3B\">" +
                                    "<p><font face=\"Verdana\" size=\"1\">");

            foreach (Windows Windows in WindowsCollection)
            {
                #region Windows_Productkey_txt.Text
                string ProductKey = "";
                try
                {
                    byte[] digitalProductId = null;
                    RegistryKey hklm = Registry.LocalMachine;
                    hklm = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
                    digitalProductId = hklm.GetValue("DigitalProductId") as byte[];
                    ProductKey = DecodeProductKey(digitalProductId);
                }
                catch (NullReferenceException)
                {
                    ProductKey = "Unknown";
                }
                #endregion

                myWindowsHtml.Text += (
                                         Windows.Caption + "<br>" +
                                         "Build Number: " + Windows.BuildNumber + " Ver: " + Windows.Version + "<br>" +
                                         "CSD Version: " + Windows.CSDVersion + "<br>" +
                                         "Install Date: " + Windows.InstallDate + "<br>" +
                                         "Country Code: " + Windows.CountryCode + "<br><br>" +
                                         "Free Physical Memory: " + Windows.FreePhysicalMemory + "<br>" +
                                         "System Up Time: " + Windows.LastBootUpTime + "<br>" +
                                         "Description: " + Windows.Description + "<br><br>" +
                                         "Licensed to:<br>" +
                                         "Registered User: " + Windows.RegisteredUser + "<br>" +
                                         "Licensed Users: " + Windows.NumberOfLicensedUsers + "<br>" +
                                         "Organization: " + Windows.Organization + "<br>" +
                                         "Serial Number: " + Windows.SerialNumber + "<br>" +
                                         "Product Key: " + ProductKey +
                                         "</font></p></body></html>"
                  );
            }

}
        }


        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        private void Close_txt_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.DocumentText = (
                                        #region Welcoming Message
                                        "<html>" +
                                        "<head>" +
                                        "<title>Conputer_ID</title>" +
                                        "<STYLE type=text/css>" +
                                        "BODY {" +
                                        "SCROLLBAR-FACE-COLOR: #637B3B; " +
                                        "SCROLLBAR-HIGHLIGHT-COLOR: #f3f3f3; " +
                                        "SCROLLBAR-SHADOW-COLOR: #f3f3f3; " +
                                        "SCROLLBAR-ARROW-COLOR: #000000; " +
                                        "SCROLLBAR-BASE-COLOR: #6d8693; " +
                                        "scrollbar-dark-shadow-color: black; " +
                                        "scrollbar-3d-light-color: #9BAAC1" +
                                        "}" +
                                        "</STYLE>" +
                                        "</head>" +
                                        "<body bgcolor=\"black\" text=\"#637B3B\" link=\"#637B3B\" vlink=\"#637B3B\" alink=\"#637B3B\">" +
                                        "<p align=\"center\"><font face=\"Verdana\" size=\"1\">Computer_ID<br>Version 2.0</font></p>" +
                                        "<p align=\"center\"><font face=\"Verdana\" size=\"1\">Made by ShoXDK</font></p>" +
                                        "<p><font face=\"Verdana\" size=\"1\">Version history:</font></p>" +
                                        "<p><font face=\"Verdana\" size=\"1\">version 2.0:<br>Given the program a new GUI, " +
                                        "cuz the old<br>one was not realy working, and rewritten the<br>code a little " +
                                        "bit, and now is should work on<br>XP and Vista.</font></p>" +
                                        "<p><font face=\"Verdana\" size=\"1\">version 1.0:<br>This first version of computer_ID, " +
                                        "was<br>really only a test, to see how it could be done.<br>And do to a weird " +
                                        "WMI call, it only worked in Vista, cuz<br>I didn't really test it on a XP machine " +
                                        ":S</font></p>" +
                                        "</body>" +
                                        "</html>"
                                        #endregion
                                        );       
            webBrowser1.Update();
        }

        private void HDD_txt_Click(object sender, EventArgs e)
        {
            CleanUP();
            GetHardDiskInfo();
            WriteHDDHtml();
            UpdateBrowser(myHDDHtml.Text);
        }

        private void CPU_txt_Click(object sender, EventArgs e)
        {
            CleanUP();
            GetCPUInfo();
            WriteCPUHtml();
            UpdateBrowser(myCPUHtml.Text);
        }

        private void Motherboard_txt_Click(object sender, EventArgs e)
        {
            CleanUP();
            GetMotboardInfo();
            WriteMainBoardHtml();
            UpdateBrowser(myMainBoardHtml.Text);
        }

        private void Graphics_txt_Click(object sender, EventArgs e)
        {
            CleanUP();
            GetGraphicsCardInfo();
            WriteGraphicsHtml();
            UpdateBrowser(myGraphicsHtml.Text);
        }

        private void Windows_txt_Click(object sender, EventArgs e)
        {
            CleanUP();
            GetWindowsInfo();
            WriteWindowsHtml();
            UpdateBrowser(myWindowsHtml.Text);
        }
    }
}